package cn.edu.swu.zwy.book;

import cn.edu.swu.zwy.db.DBTool;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;

public class AddBookServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
        String name=request.getParameter("name");
        String author=request.getParameter("author");
        Float price=Float.valueOf(request.getParameter("price"));
        String content=request.getParameter("content");
        Book book=new Book(name,author,price,content);
        try {
            BookRepo.getInstance().addBook(book);
            response.sendRedirect("./main");
        } catch (SQLException | IOException e) {
            throw new ServletException(e);
        }

    }
}
